const Koa = require("koa");
const websockify = require("koa-websocket");
const app = websockify(new Koa());
const serv = require("koa-static");
const koaBody = require("koa-body");
app.use(serv(__dirname + "/public"));
// const wsRouter = require("./router/wsRouter");
const router = require("./router/index");
let config = require('./config');

// post请求
app.use(
  koaBody({
    formLimit: "1mb",
    multipart: true, // 允许上传多个文件
    formidable: {
      maxFieldsSize: 200 * 1024 * 1024, // 文件大小
      keepExtensions: true // 保存图片的扩展名
    }
  })
);
// 中间件
app.use(require("./plugins/cros")); 
app.use(require("./plugins/token"));
app.use(require("./plugins/params"));
app.use(require("./plugins/checkAttr"));

router.initRouter(app);
// app.ws.use(wsRouter.routes()).use(wsRouter.allowedMethods());

app.listen(config.port, () => {
  console.info("http://localhost:"+config.port);
});